﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;

namespace Goldlight.Mvvm.Base.Converters
{
    [ValueConversion(typeof(string), typeof(string))]
    public class DataFormatConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string source = value.ToString();
            if (!string.IsNullOrEmpty(source))
            {
                DataFormat fmt = DataFormats.GetDataFormat(source);
                if (fmt == null)
                {
                    throw new ArgumentException("value");
                }
                return fmt;
            }
            else
            {
                throw new ArgumentNullException("value");
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }

        #endregion
    }
}
